package cn.ustb.serviceImpl;
import cn.ustb.dao.UserDao;
import cn.ustb.entity.User;
import cn.ustb.service.UserService;
import cn.ustb.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @author ljy
 */
public class UserServiceImpl implements UserService {
    @Override
    public User getUserName(String username) {
        try (SqlSession sqlSession = MyBatisUtil.getInstance()) {
            UserDao userDao = sqlSession.getMapper(UserDao.class);

            return userDao.get(username);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public void update(User user) {
        try (SqlSession sqlSession = MyBatisUtil.getInstance()) {
            UserDao userDao = sqlSession.getMapper(UserDao.class);
            userDao.update(user);
            sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
